﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PMS.Client.Entities;
using PMS.Client.IBLL;
using PMS.Client.IDAL;
using PMS.Client.Utils;

namespace PMS.Client.BLL
{
    public class FileService : ServiceBase, IFileService
    {
        IFileAccess _fileAccess;
        public FileService(IFileAccess fileAccess)
        {
            _fileAccess = fileAccess;
        }

        public int DeleteFile(string fileName)
        {
            string json = _fileAccess.DeleteFile(fileName);
            //var result = JsonUtil.Deserializer<Result<int>>(json);

            //if (result == null)
            //    throw new Exception("删除文件数据失败!");
            //if (result.state != 200)
            //    throw new Exception(result.exceptionMessage);

            //return result.data;
            return this.GetResult<int>(json);
        }

        public IEnumerable<FileEntiy> GetUpgradeFiles(string key = "")
        {
            string json = _fileAccess.GetUpgradeFiles(key);
            //var result = JsonUtil.Deserializer<Result<FileEntiy[]>>(json);

            //if (result == null)
            //    throw new Exception("文件数据获取失败!");
            //if (result.state != 200)
            //    throw new Exception(result.exceptionMessage);

            //return result.data;

            return this.GetResult<FileEntiy[]>(json);
        }

        public void UploadFile(string file, string filePath,
            Action<int> prograssChanged,
            Action<AsyncCompletedEventArgs> completed)
        {
            _fileAccess.UploadFile(file, filePath, prograssChanged, completed);
        }

        public void UploadIdCard(string file, string name)
        {
            _fileAccess.UploadIdCard(file, name);
        }

        public void UploadIssueImage(string file, string name)
        {
            _fileAccess.UploadIssueImage(file, name);
        }
    }
}
